from datetime import datetime
import requests
from pypinyin import pinyin, Style

def get_current_time() -> str:
    """
    获取当前的日期和时间。

    Returns:
        str: 当前的日期和时间，格式为 'YYYY-MM-DD HH:MM:SS'。

    Example:
        >>> get_current_time()
        '2023-10-05 14:30:00'
    """
    # 获取当前的日期和时间
    now = datetime.now()
    # 格式化日期和时间为字符串，格式为 'YYYY-MM-DD HH:MM:SS'
    current_time = now.strftime('%Y-%m-%d %H:%M:%S')
    return current_time
def get_current_weather(city):
    city_pinyin = ''.join([item[0] for item in pinyin(city, style=Style.NORMAL)])
    api_key = "d57e985b2a816028d9b4f66a4dada310"  # 替换为你的 OpenWeatherMap API 密钥
    url = f"http://api.openweathermap.org/data/2.5/weather?q={city_pinyin}&appid={api_key}&units=metric"
    response = requests.get(url)
    if response.status_code == 200:
        data = response.json()
        weather_description = data['weather'][0]['description']
        temperature = data['main']['temp']
        return f"当前{city}的天气是{weather_description}，温度为{temperature}°C。"
    else:
        return f"无法获取{city}的天气信息。"

if __name__ == '__main__':
    print(get_current_time())
    print(get_current_weather("北京"))